package com.common.basic.tags;

import java.util.Locale;
import javax.servlet.http.HttpSession;
import javax.servlet.jsp.JspException;

import com.common.basic.base.BaseTaglib;
import com.common.basic.util.Globals;

public class ButtonTaglib extends BaseTaglib 
{
	/**
	 * 
	 */
	private static final long serialVersionUID = 5496466686149751259L;
	
	private static final String styleEnabled  = "btn_e";
	private static final String styleDisabled = "btn_d";
	
	private String name;
	private String type;
	private String id;
	private String title;
	private String disabled;
	private String onclick;
	private String ondblclick;
	private String onmousemove;
	private String onmouseout;
	private String onmouseover; 
	
	
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getDisabled() {
		return disabled;
	}

	public void setDisabled(String disabled) {
		this.disabled = disabled;
	}

	public String getOnclick() {
		return onclick;
	}

	public void setOnclick(String onclick) {
		this.onclick = onclick;
	}

	public String getOndblclick() {
		return ondblclick;
	}

	public void setOndblclick(String ondblclick) {
		this.ondblclick = ondblclick;
	}

	public String getOnmousemove() {
		return onmousemove;
	}

	public void setOnmousemove(String onmousemove) {
		this.onmousemove = onmousemove;
	}

	public String getOnmouseout() {
		return onmouseout;
	}

	public void setOnmouseout(String onmouseout) {
		this.onmouseout = onmouseout;
	}

	public String getOnmouseover() {
		return onmouseover;
	}

	public void setOnmouseover(String onmouseover) {
		this.onmouseover = onmouseover;
	}

	public int doStartTag() throws JspException 
	{
		super.doStartTag();
		HttpSession session = pageContext.getSession();		
		StringBuffer sb = new StringBuffer();
		sb.append("<input ");
		if(type==null)
			sb.append("type=\"submit\" ");
		else
			sb.append("type=\"").append(type).append("\" ");
		
		if(name!=null) sb.append("name=\"").append(name).append("\" ");
		if(id!=null) sb.append("id=\"").append(name).append("\" ");
		if(title!=null)
		{
			sb.append("value=\"");
			try
			{
				sb.append(getMessage(title, null, (Locale)session.getAttribute(Globals.LOCALE_KEY)));
			}catch(Exception ex){
				sb.append(title);
			}
			sb.append("\" ");
		}
		else sb.append("value=\"\" ");
		
		
		if(disabled!=null)		
		{
			if(Boolean.valueOf(disabled).booleanValue())
				sb.append("class=\"").append(styleDisabled).append("\" disabled=\"true\" ");
			else
				sb.append("class=\"").append(styleEnabled).append("\" ");			
		}else{
			sb.append("class=\"").append(styleEnabled).append("\" ");
		}
		
		if(onclick!=null) sb.append("onclick=\"").append(onclick).append("\" ");
		if(ondblclick!=null) sb.append("ondblclick=\"").append(ondblclick).append("\" ");
		if(onmousemove!=null) sb.append("onmousemove=\"").append(onmousemove).append("\" ");
		if(onmouseout!=null) sb.append("onmouseout=\"").append(onmouseout).append("\" ");
		if(onmouseover!=null) sb.append("onmouseover=\"").append(onmouseover).append("\" ");
		sb.append("/>");
		write(pageContext, sb.toString());
		sb = null;
		return SKIP_BODY;
	}
	
}
